
package com.example.demo;

import org.junit.Test;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class GeneratorCode {


    @Test
    public void reg() {
        String packageName = "com.lplb.parenting.core";
        String[] tabPrefix = new String[]{};
        generateByTables(packageName, tabPrefix,"opera_payshare_record"
        		
        );
    }


    private void generateByTables(String packageName, String[] tabPrefix, String... tableNames) {


        // 代码生成器
        com.baomidou.mybatisplus.generator.AutoGenerator autoGenerator = new com.baomidou.mybatisplus.generator.AutoGenerator();
        // 全局配置
        com.baomidou.mybatisplus.generator.config.GlobalConfig globalConfig = new com.baomidou.mybatisplus.generator.config.GlobalConfig();
        // 数据源配置
        com.baomidou.mybatisplus.generator.config.DataSourceConfig dataSourceConfig = new  com.baomidou.mybatisplus.generator.config.DataSourceConfig();
        // 程序包配置
        com.baomidou.mybatisplus.generator.config.PackageConfig packageConfig = new com.baomidou.mybatisplus.generator.config.PackageConfig();
        // 名称策略配置
        com.baomidou.mybatisplus.generator.config.StrategyConfig strategyConfig = new com.baomidou.mybatisplus.generator.config.StrategyConfig();

        // 全局配置
        globalConfig.setActiveRecord(true);
        globalConfig.setAuthor("马行空");
        globalConfig.setOutputDir("E:\\codeGen");
        globalConfig.setFileOverride(true);
        globalConfig.setEnableCache(false);
        globalConfig.setBaseResultMap(true);
        globalConfig.setBaseResultMap(false);
        globalConfig.setBaseColumnList(false);
        
        // 数据源配置
        dataSourceConfig.setDbType(DbType.MYSQL);
        dataSourceConfig.setUrl("jdbc:mysql://47.96.14.54:3306/lplb_parenting");
        dataSourceConfig.setUsername("root");
        dataSourceConfig.setPassword("root");
        dataSourceConfig.setDriverName("com.mysql.jdbc.Driver");
        
        // 程序包配置
        packageConfig.setParent(packageName);
        packageConfig.setController("controller");
        packageConfig.setEntity("entity.opera");
        packageConfig.setService("dao.opera.service");
        packageConfig.setServiceImpl("dao.opera.service.impl");
        packageConfig.setMapper("dao.opera.mapper");
        packageConfig.setXml("dao.opera.mapper");
        
        // 名称策略配置
        strategyConfig.setTablePrefix(tabPrefix);
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setColumnNaming(NamingStrategy.nochange);
        strategyConfig.setInclude(tableNames);
        strategyConfig.setRestControllerStyle(true);
        strategyConfig.setEntityLombokModel(false);
        
        //装配
        autoGenerator.setGlobalConfig(globalConfig);
        autoGenerator.setDataSource(dataSourceConfig);
        autoGenerator.setPackageInfo(packageConfig);
        autoGenerator.setStrategy(strategyConfig);
        autoGenerator.execute();


    }
}
